package com.frame.platform.user;

import java.util.List;

import com.frame.database.PageResult;
import com.frame.pageform.PageForm;
import com.frame.pageform.component.JsonObject;
import com.frame.platform.dept.DeptDao;
import com.frame.platform.dept.Wfdept;

public class UserSelectPage extends PageForm{

	static{
		setForward("/frame/platform/user/userSelect.jsp");
		setForward("chengeshow","/frame/platform/user/userSeljs.jsp");
	}
	private String actions;
	private String deptId;
	private List selectList;
	private List seledList;

	public String execute() throws Exception {
		// TODO Auto-generated method stub
		UserDao dao=new UserDao();
		PageResult ps=dao.getUserList(null, null, getDeptId(), 300, 1);
		selectList=ps.getList();
		if("show".equals(getActions())){
			return forward("chengeshow");
		}
		return forward();
	}
	public String loadUserTree(String deptId) throws Exception{
		DeptDao ddao=new DeptDao();
		UserDao udao=new UserDao();
		List<Wfdept> dlist=ddao.getSubDept(deptId);
		String jsonstr1="",jsonstr2="";
		JsonObject json=new JsonObject();
		for(Wfdept dept:dlist){
			List<Wfdept> dlist2=ddao.getSubDept(dept.getId());
			int n=dlist2.size();
			if(n<=0){
				List<Wfuser> ulist2=udao.getDeptUserList(dept.getId());
				n=ulist2.size();
			}
			if(!"".equals(jsonstr1))jsonstr1+=",";
			jsonstr1+="{\"id\":"+json.quote(dept.getId())+",\"name\":"+json.quote(dept.getDeptname())+",\"isFolder\":\""+n+"\"}";
		}
		List<Wfuser> ulist=udao.getDeptUserList(deptId);
		for(Wfuser user:ulist){
			if(!"".equals(jsonstr2))jsonstr2+=",";
			jsonstr2+="{\"id\":"+json.quote(user.getUserid())+",\"name\":"+json.quote(user.getUsername())+"}";
		}
		json.putJsonString("depts", "["+jsonstr1+"]");
		json.putJsonString("users", "["+jsonstr2+"]");
		return json.toString();
	}

	public String getDeptId() {
		return deptId;
	}

	public void setDeptId(String deptId) {
		this.deptId = deptId;
	}

	public List getSelectList() {
		return selectList;
	}

	public void setSelectList(List selectList) {
		this.selectList = selectList;
	}

	public List getSeledList() {
		return seledList;
	}

	public void setSeledList(List seledList) {
		this.seledList = seledList;
	}

	public String getActions() {
		return actions;
	}

	public void setActions(String actions) {
		this.actions = actions;
	}


}
